home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13421 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  62 lines

  1. Path: nickel.as.arizona.edu!rwatkins
  2. From: rwatkins@nickel.as.arizona.edu (Ron Watkins)
  3. Newsgroups: comp.lang.c++
  4. Subject: Newbie question
  5. Date: 25 Mar 1996 17:26:10 GMT
  6. Organization: University of Arizona, Tucson, AZ
  7. Distribution: world
  8. Message-ID: <4j6kvi$l5a@news.ccit.arizona.edu>
  9. NNTP-Posting-Host: nickel.as.arizona.edu
  10. Keywords: memory
  11.  
  12. I am experienced in C programming and trying to learn C++. I have a question
  13. though about how to make use of class types.
  14.  
  15. In C, I can create a data structure and typedef a pointer to it (say a list).
  16. Then, the user can create as many pointers as he/she likes, then reference
  17. each one with functions to manipulate the data structures.
  18.  
  19. In C++, using classes, I don't quite see how this is done. When I layout a
  20. list datatype, I get into the following situation:
  21.  
  22. 1) Each occurance of the datatype creates a NEW list rather than linking more
  23.    nodes onto an existing list.
  24.  
  25. 2) I can't allow the user to have more than 1 occurance of my list because all
  26.    usages of the class refer to the single static pointer in the class definition.
  27.  
  28.  
  29. Please help me out here. I just don't see how to mimic C's ability as follows:
  30. (please understand, this is quick typing, not copy/paste, so there may be
  31.  slight syntax/semantic errors, im not worried about those, rather im interested
  32.  in how to do somthing similar in C++)
  33.  
  34.  
  35. typedef struct LIST {
  36.     char * value;
  37.     struct LIST * next;
  38. } * list;
  39.  
  40. func (list *) {
  41.    /* manipulate list in some way */
  42. }
  43.  
  44. /* in main (or other function) */
  45.  
  46.     list a, b;
  47.     a = (list *) malloc (sizeof (struct LIST));
  48.     b = (list *) malloc (sizeof (struct LIST));
  49.  
  50.     func (a);
  51.     func (b);
  52.  
  53. In C++, I have tried to create a class using static list and non static list.
  54. I continue to get the problems above.
  55.  
  56. e-mail to rwatkins@as.arizona.edu
  57. --
  58.  _                               
  59. |_) _ ._   \    / _._|_ | o._  _ 
  60. | \(_)| |   \/\/ (_| |_ |<|| |_> 
  61.  
  62.